# Importing Data
NAFTA<- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Plastic/Plastics.xlsx",sheet = "Sheet1", range = "e1:e70")

# Checking the Imported Data
View(NAFTA)
# Creating Time Series Data
NAFTA_ts <- ts(NAFTA, start=c(2006), end=c(2018), frequency=1)
# Viewing and Checking the Created Time Series Data
NAFTA_ts
sum(is.na(NAFTA_ts))
library(forecast)
NAFTA_ts <- tsclean(NAFTA_ts)
NAFTA_ts

# Identification: Plotting the Time Series Data
plot(NAFTA_ts)

# Estimating the appropriate model
NAFTA_ts_model <- auto.arima(NAFTA_ts)
NAFTA_ts_model

# Forecasting
options(max.print=1000000)
NAFTA_ts_forecast <- forecast (NAFTA_ts_model, level=c(95), h=22)
plot(NAFTA_ts_forecast)
NAFTA_ts_forecast             

# Exporting
write.table(NAFTA_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Plastic/NAFTA_TSA.csv", sep=",")


